/* your js go here */
$(function () {


    $("#avatar").click(function () {
        var path=$("#context-path").val();
        console.log("你点击了头像");
        window.location.href =path+'/user/user_look';
    });
    $("#lookImg").click(function () {
        $("#picFile").click();
    });
    //file表单选中文件时,让file表单的val展示到showname这个展示框
    $('#picFile').change(function () {
        var path=$("#context-path").val();
        var  f=document.getElementById("picFile").files[0];
        console.log(f);
        var data=new FormData();
        data.append("f",f);
        $.ajax({
            type: "post",
            url: path+"/user/uploadImg",
            contentType: false,
            processData: false,
            data: data,
            success: function (msg) {
                console.log(msg)
                if(null !=msg){
                    $("#lookImg").attr("src",msg);
                    $("#avatar").attr("src",msg);
                }
            },
            error: function () {

            }
        })
    });

    //用户列表，查看详情，通过class名字userDetail来找
    $(".userDetail").click(function () {
        console.log("你点击了用户详情");
        var path=$("#context-path").val();
        var uId=$(this).attr("data-id");
        var apiPath='/user/user_detail?uId='+uId;
        var url;
        if (path === ''){
            url=apiPath;
        }
        else {
            url=path+apiPath;
        }
        console.log(url);
         window.location.href = url
    });
    //关注
    $(".focus").click(function () {
        var path=$("#context-path").val();
        var fId=$(this).attr("data-fid");
        $.ajax({
            type: "get",
            url: path+"/user/focus?fid="+fId,
            success: function (data) {
                if (data === 'me'){
                    layer.msg("不能关注自己");
                    $(this).prop("checked",false)
                }
                else if (data === 'yes') {
                    layer.msg("关注成功")
                    $(this).attr("checked","checked")
                }
                else if (data === 'no') {
                    layer.msg("取关成功")
                    $(this).attr("checked","")
                }
            },
            error: function () {

            }
        })
    });
    //关注列表取消关注
    $(".un-focus").click(function () {
        console.log(111);
        var path=$("#context-path").val();
        var fid=$(this).attr("data-nfid");
        var url=path+"/user/unfocus?fid="+fid;
        window.location.href=url;
    });
    //文章收藏或取消
    $("#fav").click(function () {
        var path=$("#context-path").val();
        var artId=$(this).attr("data-artId");
        var url=path+"/article/fav?artId="+artId;
        window.location.href=url;
    });
    //发布会议跳转链接
    $("#addMeet").click(function () {
        window.location.href = '../html/meeting_add.html'
    });

    //添加文章跳转链接
    $("#addArt").click(function () {
        var path=$("#context-path").val();
        window.location.href = path+'/view/location/article_add'
    });


    $(".myList>ul>li").on("click",function () {
        if($(this).find("div").attr('class')=='list-group myGroup isHidden'){
            $(this).find("div").removeClass("isHidden")
        }else{
            $(this).find("div").addClass("isHidden")
        }


    })

    $(".table").find("input[type='checkbox']").on("click",function () {
        if($(this).prop("checked")){
            //layer.msg("关注成功")
        }else{
            //layer.msg("取关成功")

        }

    })


});

